from fastapi import APIRouter, HTTPException, Depends
from pydantic import BaseModel
from typing import Optional
from ..dependencies import get_rag_system
from ...rag.simple_rag import SimpleRAG

router = APIRouter()

class QueryRequest(BaseModel):
    question: str
    k: Optional[int] = 4

@router.post("/query")
async def query(
    request: QueryRequest,
    rag_system: SimpleRAG = Depends(get_rag_system)
):
    """查询接口"""
    try:
        result = rag_system.query(
            question=request.question,
            k=request.k
        )
        return result
    except Exception as e:
        raise HTTPException(status_code=500, detail=str(e))
